﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ResourceDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["majorid"] != null && Request.QueryString["resourceid"] != null)
        {
            string sMajorID = Request.QueryString["majorid"].ToString();
            ModelInfo modelInfo = WebMake.getModelInfo(sMajorID);

            //读取网页
            string sIndex = WebMake.getModel(modelInfo.ResourceDetail);
            //替换所有通用标签
            sIndex = WebMake.ReplaceAllTag(sIndex, modelInfo, sMajorID, Request);

            //替换资源描述部分
            SqlDataSource ds = new SqlDataSource();
            ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
            ds.SelectCommand = "select * from zyk_Resources where Resource_ID=@rsid";
            ds.SelectParameters.Add("rsid", Request.QueryString["resourceid"].ToString());
            DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
            if (dv != null & dv.Count > 0)
            {
                WebMake.addResourceVisit(dv[0]["Resource_ID"].ToString());
                sIndex = sIndex.Replace("<#RESOURCENAME>", dv[0]["Resource_Name"].ToString());
                sIndex = sIndex.Replace("<#PREVIEW>", dv[0]["Resource_PreView"].ToString());
                sIndex = sIndex.Replace("<#KEYWORD>", dv[0]["Resource_KeyWord"].ToString());
                sIndex = sIndex.Replace("<#EDITOR>", dv[0]["Resource_Editor"].ToString());
                sIndex = sIndex.Replace("<#ADDDATE>", dv[0]["Resource_AddDate"].ToString());
                sIndex = sIndex.Replace("<#EDITDATE>", dv[0]["Resource_EditDate"].ToString());
                sIndex = sIndex.Replace("<#USERID>", dv[0]["Resource_UserID"].ToString());
                sIndex = sIndex.Replace("<#SIZE>", dv[0]["Resource_Size"].ToString());
                sIndex = sIndex.Replace("<#FILETYPE>",WebMake.getFileType(dv[0]["Resource_URL"].ToString()));
                sIndex = sIndex.Replace("<#VISIT>", dv[0]["Resource_Visit"].ToString());
                sIndex = sIndex.Replace("<#COURSENAME>", WebMake.getResourceCourseName(dv[0]["Resource_ID"].ToString()));
                sIndex = sIndex.Replace("<#DOWNLOAD>", "/DownLoad.aspx?id="+dv[0]["Resource_ID"].ToString());
                sIndex = sIndex.Replace("<#DESCRIBE>", dv[0]["Resource_Describe"].ToString());
            }
            else
            {
                sIndex = "该资源不存在";
            }
            Response.Clear();
            Response.Write(sIndex);
            Response.End();
        }
    }
}
